package com.yyydjk.library.base;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.typeface.IIcon;
import com.yyydjk.library.R;
import com.yyydjk.library.beans.LibraryBean;
import com.yyydjk.library.event.SkinChangeEvent;
import com.yyydjk.library.utils.ThemeUtils;
import com.yyydjk.library.widget.MultipleStatusView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.List;

import butterknife.Bind;
import me.xiaopan.android.content.res.DimenUtils;

/**
 * Created by Administrator on 2018/4/9 0009.
 */

public abstract class BaseListFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener{
    @Bind(R.id.content_view)
    protected SwipeRefreshLayout swipeRefreshLayout;
    @Bind(R.id.swipe_target)
    protected RecyclerView recyclerView;
    @Bind(R.id.multipleStatusView)
    protected MultipleStatusView multipleStatusView;
    @LayoutRes
    protected abstract int getItemLayout();
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_base_list;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }
    @Override
    protected void initViews() {
        multipleStatusView.showLoading();
        swipeRefreshLayout.setOnRefreshListener(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    }
    protected void setIconDrawable(TextView view, IIcon icon) {
        view.setCompoundDrawablesWithIntrinsicBounds(new IconicsDrawable(getActivity())
                        .icon(icon)
                        .color(ThemeUtils.getThemeColor(getActivity(), R.attr.colorPrimary))
                        .sizeDp(20),
                null, null, null);
        view.setCompoundDrawablePadding(DimenUtils.dp2px(getActivity(), 5));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
    }
}
